
// This application uses express as it's web server
// for more info, see: http://expressjs.com
var express = require('express');
// var https = require('https');
// var bodyParser = require('body-parser');
var fs = require("fs");
// var db = require("./database");
var config = require("./config/config.json");
// var session = require('express-session');
// var cookieParser = require('cookie-parser');
var path = require('path');
// var webRouter = require('./web_router');
// var apiRouter = require('./api_router');


// var config = JSON.parse(fs.readFileSync("./config/config.json").toString());

// if(config.db) {
// 	var connection = db.open(config.db);
// }

// Create our Express application
var app = express();


// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'html');
// app.engine('html', require('ejs-mate'));
// app.locals._layoutFile = 'layout.html';
// app.enable('trust proxy');

// app.use(cookieParser());
//   app.use(session({
//     secret: '12345',
//     name: 'testapp',   //这里的name值得是cookie的name，默认cookie的name是：connect.sid
//     cookie: {maxAge: 80000 },  //设置maxAge是80000ms，即80s后session和相应的cookie失效过期
//     resave: true,
//     saveUninitialized: true,
//   }));



// Use the body-parser package in our application
// app.use(bodyParser.urlencoded({
//   extended: true
// }));
// app.use(bodyParser.json({
//   extended: true
// }));

app.use(express.static(path.join(__dirname,'public')));

// serve the files out of ./public as our main files
// if(config.publics) {
//   for(var i=0; i<config.publics.length; ++i) {
//     var localPath = __dirname + '/'+ config.publics[i];
//     app.use(express.static(localPath));
//     console.log("public at: " + localPath);
//   }
// }


// app.use('/api', apiRouter);
// app.use('/', webRouter);

// var serverOptions = {
//     key: fs.readFileSync('./privatekey.pem'),
//     cert: fs.readFileSync('./certificate.pem')
// };

// https.createServer(serverOptions, app).listen(config.http.port, function () {
//     console.log('Https server listening on port ' + config.http.port);
// });

// start server on the specified port and binding host
app.listen(config.http.port, /*config.http.host, */function() {
  var url =config.http.host + ":"+config.http.port;
	// print a message when the server starts listening
  console.log("server starting on " + url);
});


